﻿using AMMVVMLibrary.Portable;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

namespace AMMVVMLibrary.W8
{
    public static class PageExtensions
    {
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="DataContextClass"></typeparam>
        /// <param name="page"></param>
        /// <param name="e"></param>
        public static void PassParametersToViewModel<DataContextClass>(this Page page, NavigationEventArgs e, object parameter) where DataContextClass : ViewModelBase
        {
            if (e.NavigationMode == NavigationMode.New || e.NavigationMode == NavigationMode.Refresh)
            {
                var viewModel = page.DataContext as DataContextClass;
                if (viewModel != null)
                {
                    viewModel.LoadData(parameter);
                }
            }
        }
    }
}
